<template>
  <div id="container" ref="container">
    <div class="introduce" v-show="!isContainer">欢迎页</div>
    <div class="container" v-show="isContainer">
      <div class="navContainer" v-show="isNavContainer">
        <router-link to="/info" active-class="active" class="nav">
          <img ref="toInfo" :src="infoSrc" style="width: 20px" alt="">
        </router-link>
        <div class="sonNavContainer">
          <router-link to="/square" active-class="active" class="nav">广场</router-link>
          <router-link to="/recommend" active-class="active" class="nav">推荐</router-link>
          <router-link to="/find" active-class="active" class="nav">发现</router-link>
        </div>
        <router-link to="/search" active-class="active" class="nav">
          <img ref="toSearch" :src="searchSrc" style="width: 20px" alt="">
        </router-link>
      </div>
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </div>
  </div>
</template>

<script>

export default {
  name: 'App',
  data() {
    return {
      isContainer: false,
      isNavContainer: true,
      infoSrc: require('./assets/info.png'),
      searchSrc: require('./assets/search.png'),
    }
  },
  methods: {},
  mounted() {
    setTimeout(() => {
      this.isContainer = true
    }, 500)
    //点击我的显示我的界面，隐藏nav
    this.$refs.toInfo.addEventListener('click', () => {
      this.isNavContainer = false
    })
    //点击搜索显示搜索界面，隐藏nav
    this.$refs.toSearch.addEventListener('click', () => {
      this.isNavContainer = false
    })
    //展示nav
    this.$bus.$on('showNav',(value)=>{
      this.isNavContainer = value
    })
  }
}
</script>

<style>
#container {
  width: 100%;
  min-height: 844px;
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ebfcf4), to(#ffefef)); /*背景颜色*/
  position: relative;
}

.navContainer {
  position: sticky;
  z-index: 999;
  top: 10px;
  width: 90%;
  margin-left: 5%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sonNavContainer {
  width: 60%;
  height: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.nav {
  font-size: 15px;
  line-height: 25px;
  color: black;
}

.active {
  font-size: 18px;
  font-weight: bold;
}
</style>
